<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>购物车列表</title>
    <style type="text/css">
        * {
            font-size: 11pt;
        }

        div {
            margin: 20px;
            border: 2px solid gray;
            width: 150px;
            height: 150px;
            text-align: center;
        }

        li {
            margin: 10px;
        }

        img {
            height: 150px;
            width: 150px;
        }
    </style>
</head>
<body>
<h1>购物车</h1>
<c:choose>
    <c:when test="${empty sessionScope.cart or fn:length(sessionScope.cart.cartItems ) eq 0}">
        <img src="<c:url value='/img/cart.jpg'/>"/>
    </c:when>
    <c:otherwise>
        <table border="1" width="100%" cellspacing:
        "0" background="black">
        <tr>
            <td colspan="7" align="right" style="font-size: 15pt; font-weight: 900">
                <a href="<c:url value='/CartServlet?method=clear'/>">清空购物车</a>
            </td>
        </tr>
        <tr>
            <th>图片</th>
            <th>书名</th>
            <th>作者</th>
            <th>单价</th>
            <th>数量</th>
            <th>小计</th>
            <th>操作</th>
        </tr>
        <c:forEach items="${sessionScope.cart.cartItems }" var="cartItem">
            <tr>
                <td>
                    <div>
                        <img src="<c:url value='/${cartItem.book.image }'/>">
                    </div>
                </td>
                <td>${cartItem.book.bname }</td>
                <td>${cartItem.book.author }</td>
                <td>${cartItem.book.price }元</td>
                <td>${cartItem.count }</td>
                <td>${cartItem.subtotal }元</td>
                <td><a href="<c:url value='/CartServlet?method=delete&bid=${cartItem.book.bid }'/>">删除</a></td>
            </tr>
        </c:forEach>
        <tr>
            <td colspan="7" align="right" style="font-size: 15pt; font-weight: 900">合计：${sessionScope.cart.total }元</td>
        </tr>
        <tr>
            <td colspan="7" align="right" style="font-size: 15pt; font-weight: 900">
                <a href="<c:url value='/OrderServlet?method=add'/>">结算</a>
            </td>
        </tr>
        </table>
    </c:otherwise>
</c:choose>
</body>
</html>